<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <style type="text/css">
        html{height:100%}
        body{height:100%;margin:0px;padding:0px}
        #container{height:85%}
    </style>
    <link rel="stylesheet" href="/resources/layui/css/layui.css">
    <script rel="stylesheet" src="/resources/layui/layui.js"></script>
    <script rel="stylesheet" src="/resources/js/jquery.min.js"></script>
    <script src="/resources/js/function/Local.js"></script>
    <!--核心插件-->
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=32mOZToZ1kGRUDb1oRy6IjT32eqxH3pa"></script>
    <!--绘制图案-->
    <script type="text/javascript" src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js"></script>
    <link rel="stylesheet" href="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css" />
    <style type="text/css">
        #container{height:70%}
        .BMap_cpyCtrl {
            display: none;
        }
        .anchorBL {
            display: none;
        }
    </style>
</head>
<body>
<form class="layui-form" id="formone" action="">
    <div class="layui-inline">
        <label class="layui-form-label">选择定区</label>
        <div class="layui-input-inline">
            <select id="dingqv" name="dingqv"  lay-verify="required" lay-search="">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">详细地址</label>
        <div class="layui-input-inline">
            <input type="text" name="xiangxi" id="xiangxi" placeholder="请输入详细地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <button type="button" class="layui-btn" onclick="tijiao()" lay-submit="" lay-filter="demo1">查询</button>
</form>
<div id="r-result"><input type="hidden" id="suggestId" size="20" value="百度" style="width: 150px;"/> </div>
<div id="container"></div>
<div id="searchResultPanel" style="border:1px solid #c0c0c0;width:150px;height: auto; display:none;"></div>
</body>
<script>
    $.get(new Local().base_url+"/qvyv/show",function(data) {
        $.each(data.data, function () {
            var opt = $("<option></option>").appendTo("#dingqv");
            opt.text(this.sheng+this.shi+this.qv).val(this.id);
        });
    });
</script>
</html>
<script>
    var table,form,layer,laytpl;
    layui.use(['table','form','laytpl','layer'], function() {
        table = layui.table;
        form = layui.form;
        layer = layui.layer;
        laytpl = layui.laytpl;
    });
</script>
<script>
    var map = new BMap.Map("container");
    var point = new BMap.Point(116.404, 39.916);
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
    map.centerAndZoom(point, 15);
</script>
<script>
    initial();
    function initial(){
        $.post(new Local().base_url+"/qvpaidian/show",function(d){
            var data=d.data;
            $.each(data,function(shu){
                var d=this;
                var pp=new BMap.Point(d.jingdu,d.weidu);
                map.centerAndZoom(pp,18);
                var marker=new BMap.Marker(pp);
                map.addOverlay(marker);
                var optis={
                    width:150,
                    title:'详细信息',
                    enableMessage:true//设置允许信息窗发送信息
                };
                var infoWindow=new BMap.InfoWindow("地址:"+d.quyv.sheng+d.quyv.shi+d.quyv.qv+d.xiangxi+"</br>坐标:["+pp.lng+","+pp.lat+"]</br>派送员:"+d.qvpai.name+"</br>联系电话:"+d.qvpai.phone,optis);
                marker.addEventListener("click",function(){
                    map.openInfoWindow(infoWindow,pp);//开启信息窗口
                });
               /* var removeMarker=function(e,ee,marker){
                    //右键菜单
                    $("#yuangong").val(d.qvpai.id);
                    layui.layer.msg("已设置取派员");
                };
                //创建右键菜单
                var markerMenu=new BMap.ContextMenu();
                markerMenu.addItem(new BMap.MenuItem('设置为取派点',removeMarker.bind(marker)));
                marker.addContextMenu(markerMenu);*/
                marker.setAnimation(BMAP_ANIMATION_BOUNCE);
            });
        });
    }
</script>


<!--查询地址-->
<script>
    var Ding;
    var xx;
    var dingqvid;
    function tijiao(){
        dingqvid=$("#dingqv").val();
        Ding=Ding=$("#dingqv option[value="+dingqvid+"]").text();
        xx=$("#xiangxi").val();
        setPlacel(Ding+xx);
    }

</script>
<script>
    function setPlacel(t){
        //map.clearOverlays();
        function myFun(){
            var dingqvid=$("#dingqv").val();
            var Ding=$("#dingqv option[value="+dingqvid+"]").text();
            var xx=$("#xiangxi").val();
            var pp=local.getResults().getPoi(0).point;
            map.centerAndZoom(pp,18);
            var marker=new BMap.Marker(pp);
            map.addOverlay(marker);
            var optis={
                width:150,
                height:80,
                title:'详细信息',
                enableMessage:true//设置允许信息窗发送信息
            };
            var infoWindow=new BMap.InfoWindow("地址:"+Ding+xx+"</br>坐标:["+pp.lng+","+pp.lat+"]",optis);
            marker.addEventListener("click",function(){
                map.openInfoWindow(infoWindow,pp);//开启信息窗口
            });
            var removeMarker=function(e,ee,marker){
                $.get('add.html',function (s) {
                    //parent
                    layer.open({
                        type : 1,
                        title : '分配员工',
                        area:'70%',
                        content:s,
                        btn : ['确定','取消'],
                        success:function(){
                            $("#jingdu").val(e.lng);
                            $("#weidu").val(e.lat);
                            $("#bianhao").val(dingqvid);
                            $("#xiangxi2").val(xx);
                            form.render();
                        }
                        ,yes:function(){
                            var str = $("#form").serialize();
                            $.post(new Local().base_url+"/qvpaidian/add",str,function(data){
                                layer.close(layer.index);
                                map.clearOverlays();
                                layer.msg("区域添加成功!",function(){
                                    location.reload()
                                });
                            });
                        }
                    });
                });
            };
            //创建右键菜单
            var markerMenu=new BMap.ContextMenu();
            markerMenu.addItem(new BMap.MenuItem('设置为取派点',removeMarker.bind(marker)));
            marker.addContextMenu(markerMenu);
        }
        var local=new BMap.LocalSearch(map,{
            //智能搜索
            onSearchComplete:myFun
        });
        local.search(t);
    }
</script>